#ifndef _V_CLASS_SimpleFileStream_INCLUDED_
#define _V_CLASS_SimpleFileStream_INCLUDED_

#include "IFileStream.h"
#include "ISimpleFileStream.h"

class SimpleFileStream : 
		public IFileStream,
		public ISimpleFileStream
{
public:
	BEGIN_DEFINE_CLASS(CLSID_SimpleFileStream)
		DEFINE_INTERFACE_ENTRY(IFileStream)
		DEFINE_INTERFACE_ENTRY(ISimpleFileStream)
	END_DEFINE_CLASS()

public:
	SimpleFileStream();
	virtual ~SimpleFileStream();

public:	//IFileStream
	virtual vresult Close();
	virtual vresult Flush();

	inline virtual bool CanSave(){return true;}
	inline virtual bool CanLoad(){return true;}
	virtual vresult SaveByte(byte by);
	virtual vresult LoadByte(byte* pByte);

	virtual vresult SaveData(const byte* pByte,long lDataLen,long* pDataSaved);
	virtual vresult LoadData(byte* pByte,long lDataLen,long* pDataLoaded);

	virtual long GetCurrentPos();
	virtual vresult Seek(kSeekMode mode,long nNewPos);
	
	virtual long GetStreamLength();
	virtual vresult SetStreamLength(long lNewLength);

public:	//ISimpleFileStream
	virtual vresult OpenFile(const wchar_t* sFileName,bool bCreate,bool bTruncate_existing);
	vresult SimpleFileStream::OpenFile(const wchar_t* sFileName,kDocOp docop);
	virtual HANDLE ReleaseFileHandle();
private:
	void RefereshMapView(long lDataLen);
	vresult InitMappingFile(uint32 dwMapAccess, uint32 dwViewAccess);
protected:
	HANDLE				m_hFile;
	long				m_lCurPos;
	long				m_lLength;
private:
	long	m_lGran;
	HANDLE	m_hFileMap;
	byte*	m_pData;
	long	m_lFileOffset;
	long	m_lDataLength;
	bool	m_bIsNetFile;
};

#endif	//_V_CLASS_SimpleFileStream_INCLUDED_
